package com.shelpe.service.simbaproxy.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.shelpe.service.simbaproxy.client.AuthClient;
import com.shelpe.service.simbaproxy.filter.APIInvokeMetricFilter;
import com.shelpe.service.simbaproxy.filter.ContentTypeFilter;
import com.shelpe.service.simbaproxy.filter.ErrorFilter;
import com.shelpe.service.simbaproxy.taobao.APIParameterBuilderFilter;
import com.shelpe.service.simbaproxy.taobao.PreValidateFilter;
import com.shelpe.service.simbaproxy.taobao.TaobaoAPIService;
import com.shelpe.service.simbaproxy.taobao.TaobaoAPIServiceImpl;
import com.shelpe.service.simbaproxy.taobao.TaobaoPropertiesProvider;

@Configuration
@Profile("product")
public class ProxyConfiguration {

	@Bean
	public TaobaoAPIService taobaoService(TaobaoPropertiesProvider props){
		TaobaoAPIServiceImpl service = new TaobaoAPIServiceImpl();
		service.setProp(props);
		return service;
	}
	@Bean
	public APIParameterBuilderFilter taobaoParamsFilter(TaobaoAPIService taobaoAPIService, AuthClient authService, ObjectMapper objectMapper){
		APIParameterBuilderFilter filter =  new APIParameterBuilderFilter();
		filter.setAuthClient(authService);
		filter.setTaobaoAPIService(taobaoAPIService);
		filter.setObjectMapper(objectMapper);
		return filter;
	}
	@Bean
	public ContentTypeFilter contentTypeFilter(){
		return new ContentTypeFilter();
	}
	@Bean
	public ErrorFilter errorFilter(){
		return new ErrorFilter();
	}
	@Bean
	public PreValidateFilter preValidateFilter(){
		return new PreValidateFilter();
	}
	@Bean
	public APIInvokeMetricFilter apiInvokeMetricFilter(){
		return new APIInvokeMetricFilter();
	}
}
